package com.lfz.quality_effect.constant;

import com.lfz.quality_effect.exception.MyException;
import com.lfz.quality_effect.utils.ReturnCode;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class LfzConstant {

    public final static String LEPU_COURT="乐平市";
    public final static String CHANGJIANG_COURT="昌江区";
    public final static String ZHUSHAN_COURT="珠山区";
    public final static String FULIANG_COURT="浮梁县";


    public final static Integer LFZ_ZERO=0;

    public final static Integer LFZ_ONE=1;

    public static List<String> getInitCourtList(){
        List<String> courtList = new ArrayList<>();
        courtList.add("乐平市人民法院");
        courtList.add("景德镇市昌江区人民法院");
        courtList.add("景德镇市珠山区人民法院");
        courtList.add("浮梁县人民法院");
        return courtList;
    }

    /**
     * 获取裕量
     * @param indexName
     * @param indexValue
     */
    public static String getMargin(String indexName, String indexValue,String scoreCriteria) {
        String result = null;
        if ("基层治理单位入驻比".equals(indexName)){
            BigDecimal value = new BigDecimal(indexValue);
            BigDecimal score = new BigDecimal(scoreCriteria);
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin.toString();
        }else if ("音视频调解纠纷占比".equals(indexName)){
         BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";


        }else if ("诉前调解分流率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";

        }else if ("道交一体化平台应用率".equals(indexName)){
            //指标得分
            String[] indexArray =indexValue.replace("%","").split("\\|");
            String[] scoreCriteriaArray = scoreCriteria.replace("%","").split("\\|");
            if (indexArray.length != scoreCriteriaArray.length){
                throw new MyException(ReturnCode.RC10003.getCode(),"道交一体化平台应用率"+ReturnCode.RC10003.getMsg());
            }
            //必须每一项都符合才
            for (int i=0;i<indexArray.length;i++){
                BigDecimal score = new BigDecimal(indexArray[i]);

                BigDecimal value =   new BigDecimal(scoreCriteriaArray[i]);
                BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
                result= margin+"%|";
            }
            result = result.substring(0,result.length()-1);
        }else if ("诉前调解成功率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";

        }else if ("诉前调解纠纷平均委派时长".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("天",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("天",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"天";
        }else if ("诉前调解纠纷平均办理时长".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("天",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("天",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"天";
        }else if ("调解人员月成功调解纠纷数".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("件/人月",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("件/人月",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin.toString();
        }else if ("“总对总”委派成功案件数占诉前调解案件比".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("“总对总”对接单位调解成功率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("基层治理单位受理纠纷比".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("基层治理单位调解化解成功率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("分调裁审案件占比".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("速裁、快审案件平均审理期限".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("天",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("天",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin.toString();
        }else if ("网上立案超期审核率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("管辖法院反馈时间".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("分钟",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("分钟",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin.toString();
        }else if ("人民法院律师服务平台综合应用率-网上立案率+事项申请率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("人民法院律师服务平台综合应用率-安检一码通使用率".equals(indexName)){

            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("人民法院律师服务平台综合应用率-开庭排期自动避让率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("律师服务平台超期未办理占比".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("诉讼服务业务满意度评价".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("立案庭长每日使用诉服指导中心平台率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("电子送达率".equals(indexName)){

            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";
        }else if ("在线委托鉴定率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";

        }else if ("在线办理保全率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";

        }else if ("网上保全平均办理时长-诉前保全".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("小时",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("小时",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin.toString();

        }else if ("网上保全平均办理时长-诉讼保全".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("天",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("天",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin.toString();

        }else if ("网上交费占应交费案件比".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";

        }else if ("阅卷申请审核率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";

        }else if ("网上阅卷成功率".equals(indexName)){
            BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
            BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
            BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
            result= margin+"%";

        }
        return result;
    }

    public static void main(String[] args) {
//        String indexValue = "100%";
//        String scoreCriteria = "90%";
//        BigDecimal value =   new BigDecimal(indexValue.replace("%",""));
//        BigDecimal score = new BigDecimal(scoreCriteria.replace("%",""));
//        BigDecimal a = value.subtract(score);
//        System.out.println(a);
//        BigDecimal b = a.multiply(score);
//        BigDecimal margin = (value.subtract(score)).divide(score,2, RoundingMode.HALF_UP);
//        System.out.println(margin.toString());
        String a = "63.82%|82.99%|32.13%";
      String b =  a.replace("%","");
     String[] aa = b.split("\\|");
        System.out.println(b);
    }
}
